package com.xinmao.quantitative.trad.backtesting;

import org.ta4j.core.BarSeries;
import org.ta4j.core.Rule;
import org.ta4j.core.indicators.CCIIndicator;
import org.ta4j.core.rules.OverIndicatorRule;
import org.ta4j.core.rules.UnderIndicatorRule;

public class CCICorrectionBackTest
{
    public static Rule createEntryRule(BarSeries series, int shortBarCount, int longBarCount) {
        CCIIndicator longCci = new CCIIndicator(series, longBarCount);
        CCIIndicator shortCci = new CCIIndicator(series, shortBarCount);

        return  new OverIndicatorRule(longCci, 100) // Bull trend
                        .and(new UnderIndicatorRule(shortCci, -100)); // Signal
    }

    public static Rule createExitRule(BarSeries series, int shortBarCount, int longBarCount) {
        CCIIndicator longCci = new CCIIndicator(series, longBarCount);
        CCIIndicator shortCci = new CCIIndicator(series, shortBarCount);

        return new UnderIndicatorRule(longCci, -100) // Bear trend
                        .and(new OverIndicatorRule(shortCci, 100));
    }
}
